home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HyperLib 1997 Winter - Disc 1
/
HYPERLIB-1997-Winter-CD1.ISO.7z
/
HYPERLIB-1997-Winter-CD1.ISO
/
オンラインウェア
/
UTIL
/
Folder・Icon・Opener 1.0.1.sit
/
Folder•Icon•Opener 1.0.1
/
source code
/
sources
/
FIOpen.main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-05-05
|
7KB
|
250 lines
/*
*--------------------------------------------------------------
* FIOpen.main.c
*--------------------------------------------------------------
* Copyright ゥ Fumio Rokkaku, 1996
*--------------------------------------------------------------
*/
#pragma once
/* System Headers */
#include <Memory.h>
#include <QuickDraw.h>
#include <Events.h>
#include <Windows.h>
#include <Dialogs.h>
#include <AppleEvents.h>
#include <OSUtils.h>
#include <Processes.h>
#include <Files.h>
#include <Aliases.h>
#include <Processes.h>
#include <Errors.h>
/* Project Headers */
#include "FIOpen.h"
static void InitMacintoshToolbox(void);
static void DoMyJob(void);
static void DoMouseDown(EventRecord *);
static void DoKeyDown(EventRecord *);
static void DoDrag(WindowRef, Point);
static void DoGoAway(WindowRef, Point);
static void DoIdleTasks(void);
/*
*--------------------------------------------------------------
* global flags to determe current condition
*--------------------------------------------------------------
*/
Boolean gDone;
Boolean gForeground;
Boolean gDragAndDrop;
Boolean gDoubleClick;
/*
*--------------------------------------------------------------
* main
*--------------------------------------------------------------
*/
void main(void)
{
InitMacintoshToolbox();
GetQuickDrawVersion();
if (SetUpMyMenus()
&& SetUpMyAppleEvent()
&& SetUpMyEditor()) {
DoMyJob();
}
}
/*
*--------------------------------------------------------------
* InitMacintoshToolbox
*--------------------------------------------------------------
* standard intialization
*--------------------------------------------------------------
*/
static void InitMacintoshToolbox(void)
{
int i;
MaxApplZone();
for (i = 0; i < 15; i++) MoreMasters();
InitGraf(&qd.thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(0);
InitCursor();
FlushEvents(everyEvent, 0);
}
/*
*--------------------------------------------------------------
* DoMyJob
*--------------------------------------------------------------
* do my main job
*--------------------------------------------------------------
*/
static void DoMyJob(void)
{
EventRecord anEvent;
gDone = false;
gForeground = true;
do {
if (WaitNextEvent(everyEvent, &anEvent, 120, nil)) {
if (IsDialogEvent(&anEvent)) {
DoDialogs(&anEvent);
}
else switch(anEvent.what) {
case mouseDown: DoMouseDown(&anEvent); break;
case keyDown:
case autoKey: DoKeyDown(&anEvent); break;
case kHighLevelEvent: AEProcessAppleEvent(&anEvent); break;
}
} else {
DoIdleTasks();
}
} while (!gDone);
}
/*
*--------------------------------------------------------------
* DoMouseDown
*--------------------------------------------------------------
* mouse down event handler
*--------------------------------------------------------------
*/
static void DoMouseDown(EventRecord *theEvent)
{
WindowRef aWindow;
short whichPart = FindWindow(theEvent->where, &aWindow);
switch (whichPart) {
case inMenuBar: DoMenus(MenuSelect(theEvent->where)); break;
case inSysWindow: SystemClick(theEvent, aWindow); break;
case inDrag: DoDrag(aWindow, theEvent->where); break;
case inGoAway: DoGoAway(aWindow, theEvent->where); break;
}
}
/*
*--------------------------------------------------------------
* DoKeyDown
*--------------------------------------------------------------
* accept keyboard command
*--------------------------------------------------------------
*/
static void DoKeyDown(EventRecord *theEvent)
{
int charCode = theEvent->message & charCodeMask;
int keyCode = (theEvent->message & keyCodeMask) >> 8;
if (theEvent->modifiers & cmdKey) {
DoMenus(MenuKey(charCode));
}
}
/*
*--------------------------------------------------------------
* DoOSEvent
*--------------------------------------------------------------
* suspend and resule event handling
*--------------------------------------------------------------
*/
void DoOSEvent(EventRecord *theEvent)
{
short messageKind = (theEvent->message >> 24) & 0xff;
short messageFlag = theEvent->message & 0xff;
if (messageKind == suspendResumeMessage) {
gForeground = ((messageFlag & resumeFlag) != 0);
}
}
/*
*--------------------------------------------------------------
* DoMountDisk
*--------------------------------------------------------------
* disk mount check
*--------------------------------------------------------------
*/
void DoMountDisk(EventRecord *theEvent)
{
long diskMessage = theEvent->message;
if (HiWord(diskMessage) != noErr) {
Point warningPos;
warningPos.v = warningPos.h = 64;
DILoad();
DIBadMount(warningPos, diskMessage);
DIUnload();
}
}
/*
*--------------------------------------------------------------
* DoDrag
*--------------------------------------------------------------
* drag any of window
*--------------------------------------------------------------
*/
static void DoDrag(WindowRef theWindow, Point where)
{
Rect maxRect;
InitCursor();
if ((FrontWindow() != theWindow) && (IsKeyPressed(kCommandKey) == false)) {
SelectWindow(theWindow);
}
maxRect = (**(GetGrayRgn())).rgnBBox;
InsetRect(&maxRect, 4, 4); /* limit draggable area */
DragWindow(theWindow, where, &maxRect);
}
/*
*--------------------------------------------------------------
* DoGoAway
*--------------------------------------------------------------
* handle close box
*--------------------------------------------------------------
*/
static void DoGoAway(WindowRef theWindow, Point where)
{
if (TrackGoAway(theWindow, where)) {
if (GetWRefCon(theWindow) == kAboutType) {
CloseAboutDialog();
}
}
}
/*
*--------------------------------------------------------------
* DoIdleTasks
*--------------------------------------------------------------
* do jobs on null event
*--------------------------------------------------------------
*/
static void DoIdleTasks(void)
{
if (gDragAndDrop && !gDoubleClick) {
/* quit when launched with drag and drop from Finder */
gDone = true;
}
else if (gForeground) {
AdjustMyMenus();
InitCursor();
}
}
/*
*--------------------------------------------------------------
* IsKeyPressed
*--------------------------------------------------------------
* check if the key is pressed
*--------------------------------------------------------------
*/
Boolean IsKeyPressed(const unsigned short theKey)
{
KeyMap aMap;
GetKeys(aMap);
return ((((unsigned char *)aMap)[theKey >> 3] >> (theKey & 7)) & 1);
}